package com.gxuwz.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxuwz.medical.domain.medical.Medical;



public class MedicalServlet extends BaseServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String  m=request.getParameter("m");//动作类型参数
		if("list".equals(m)){
			process(request, response, "/page/medical/medical_list.jsp");
		}else if("input".equals(m)){
			process(request, response, "/page/medical/medical_add.jsp");
		}else if("get".equals(m)){
			
			process(request, response, "/page/medical/medical_edit.jsp");
		}else if("add".equals(m)){
			add(request, response);
			process(request, response, "/page/medical/medical_list.jsp");
		}else if("del".equals(m)){
		    del(request, response);
		    }else if ("edit".equals(m)) {
			edit(request, response);
		}else {
			error(request, response);
		}
	}
	/**
	 * 添加机构方法
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	private void add(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException{
		 //接收页面传递过来的参数
		 String medicalid=request.getParameter("medicalid");
		 String medicalname=request.getParameter("medicalname");
		 //实例化Medical类
		 Medical medical =new Medical();
		 //调用添加方法
		 try{
			 medical.addMed(medicalid, medicalname);
		 }catch(Exception e){
			 error(request, response);
		 }
		 
	}
	protected void del(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		try{
			String medicalid = request.getParameter("id");
		//1:实例化Medical
			Medical medical =new Medical();
		//2:调用方法
			System.out.print(medicalid);
			medical.delMed(medicalid);
			process(request, response, "/page/medical/medical_list.jsp");
		}catch(Exception e){
			e.printStackTrace();
		}	
		
	}
	protected void edit(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try{
		String medicalid = request.getParameter("medicalid");
		String medicalname = request.getParameter("medicalname");
		//1:实例化Medical
		Medical medical=new Medical(medicalid);
		//2:调用方法
		
		medical.editMed(medicalname);
			process(request, response, "/page/medical/medical_list.jsp");
		}catch(Exception e){
			e.printStackTrace();
		}	
		
	}

}

